package com.spc.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.spc.dao.HealthAssessmentDao;
import com.spc.entity.PageResult;
import com.spc.entity.QueryPageBean;
import com.spc.pojo.Heart;
import com.spc.pojo.HeartChoose;
import com.spc.service.HealthAssessmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = HealthAssessmentService.class)
@Transactional
public class HealthAssessmentServiceImpl implements HealthAssessmentService {


    @Autowired
    private HealthAssessmentDao healthAssessmentDao;
    //分页查询
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {

        String queryString = queryPageBean.getQueryString();
        Integer pageSize = queryPageBean.getPageSize();
        Integer currentPage = queryPageBean.getCurrentPage();

        //利用分页助手进行分页
        PageHelper.startPage(currentPage,pageSize);
        //进行条件查询
        Page<Heart> page = healthAssessmentDao.findBycondition(queryString);
        //获取总数据数和当前分页页面的数据
        long total = page.getTotal();
        List<Heart> rows = page.getResult();

        return new PageResult(total,rows);
    }

    //根据id查询对应的数据，进行数据回显
    @Override
    public Heart findById(Integer id) {
     Heart heart = healthAssessmentDao.findById(id);
        return heart;
    }

    //根据用户id和表单数据修改数据
    @Override
    public void edit(Heart heart) {
        healthAssessmentDao.edit(heart);
    }

    //根据用户id删除数据
    @Override
    public void delete(Integer id) {
        healthAssessmentDao.delete(id);
    }

    //查询所有的心理测评问题
    @Override
    public List<HeartChoose> findAll() {
        List<HeartChoose> list = healthAssessmentDao.findAll();

        return list;
    }
}
